#ifndef __CM_BASE_BASE_TIMER_H__
#define __CM_BASE_BASE_TIMER_H__

#include "BaseNotification.h"

#include "Poco/TimedNotificationQueue.h"
#include "Poco/Runnable.h"
#include "Poco/Thread.h"

using Poco::Thread;
using Poco::Runnable;
using Poco::TimedNotificationQueue;

namespace cm_base
{
    class TimerNotification;

    class BaseTimerListener
    {
    public:
        virtual void onTimer(TimerNotification* p_tn ) = 0;        
    };

    class TimerNotification: public BaseNotification
    {
    public:
        TimerNotification();
        virtual ~TimerNotification();

        void setInterval( long interval);
        long getInterval();

        void setContext(UInt32 context);
        UInt32 getContext();

        void registerListener( BaseTimerListener* p_listener );

    protected:
        long m_interval;
        UInt32 m_context;
        BaseTimerListener* m_listener;

        friend class BaseTimer;
    };

    class BaseTimer: public Runnable
    {
    public:
        BaseTimer();
        ~BaseTimer();

        int setup();
        int teardown();

        void start( TimerNotification* p_tn );
        void start( long interval, UInt32 context, BaseTimerListener* p_cbListener );

        void run();

    protected:
        TimedNotificationQueue m_queue;
        bool m_stopFlag;

        Thread m_thread;
    };
}


#endif